<template>
  <div id="deviceLog">
    <div class="dev-nav">
      <p>设备日志</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>出入管理</el-breadcrumb-item>
        <el-breadcrumb-item>门禁设备</el-breadcrumb-item>
        <el-breadcrumb-item>设备日志</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search">
      <el-input v-model="input" placeholder="触发原因"></el-input>
      <!-- 日历 -->
      <div class="block">
        <!-- <span class="demonstration">默认</span> -->
        <el-date-picker
          class="block-content"
          v-model="value1"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
      <!-- 查询 -->
      <el-button
        type="success"
        style="background-color: #0bb197"
        @click="inquire"
      >
        <i class="el-icon-search"></i>
        查询</el-button
      >
      <el-button type="success" plain class="reset" @click="reset">
        <i class="el-icon-refresh"></i>
        重置</el-button
      >
    </div>
    <!-- 表格内容 -->
    <div class="dev-content">
      <p>查询结果列表</p>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="序号" width="180" align="center">
        </el-table-column>
        <el-table-column
          prop="reason"
          label="触发原因"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column label="触发时间" align="center">
          <template slot-scope="scope">
            <span>{{ timeTrans(scope.row.tiggerTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="deviceName" label="上报设备" align="center">
        </el-table-column>
        <el-table-column prop="eventType" label="事件类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.eventType == 0">环境影响</span>
            <span v-if="scope.row.eventType == 1">自然发展</span>
          </template>
        </el-table-column>
        <el-table-column prop="eventDesc" label="描述" align="center">
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :background="true"
        class="msg-pagination-container"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="count"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import time from "../utils/time";
export default {
  mixins: [time],
  data() {
    return {
      page: 1,
      count: 5,
      total: 1,
      input: "",
      tableData: [],
      // 日历
      value1: [],
      startTime: "",
      endTime: "",
    };
  },
  methods: {
    handleSizeChange(val) {
      this.count = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },

    // 渲染数据
    getData() {
      this.value1[0] && (this.startTime = this.timeTrans(this.value1[0]));
      this.value1[1] && (this.endTime = this.timeTrans(this.value1[1]));
      this.$axios({
        url: "/smart/device-log/list",
        method: "get",
        params: {
          pageNum: this.page,
          pageSize: this.count,
          reason: this.input,
          startTime: this.startTime,
          endTime: this.endTime,
        },
      }).then(({ data }) => {
        if (data.code == 2000) {
          // console.log("pppp", data);
          this.tableData = data.data.list;
          this.total = data.data.total;
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },
    // 查询
    inquire() {
      this.getData();
    },
    // 重置
    reset() {
      this.input = "";
      this.value1 = [];
      this.startTime = "";
      this.endTime = "";
      this.getData();
      this.$message.success("重置成功");
    },
  },
  mounted() {
    this.getData();
  },
};
</script>


<style lang="less" scoped>
#deviceLog {
  padding: 20px;
  // background-color: #f3f3f4;
  // border: 1px solid red;
  .dev-nav {
    display: flex;
    justify-content: space-between;
  }
  p {
    font-size: 18px;
    margin: 0;
  }
  .search {
    margin: 20px 0px;
    padding: 20px 15px;
    display: flex;
    align-items: center;
    background-color: white;
    border-radius: 8px;
    .el-input {
      width: 150px;
      margin-right: 20px;
    }
    .reset {
      background-color: white;
      color: #c0c4cc;
      border: 1px solid #c0c4cc;
    }
    .reset:hover {
      color: #0bb197;
    }
    .block {
      margin-right: 20px;
      .block-content {
        width: 310px;
      }
    }
    .el-button {
      padding: 10px 15px;
      margin-left: 0px;
      margin-right: 20px;
    }
  }
  .dev-content {
    padding: 20px 15px;
    padding-bottom: 30px;
    background-color: white;
    border-radius: 8px;
    p {
      font-size: 16px;
      margin-bottom: 10px;
    }
    .el-pagination {
      text-align: end;
      margin-top: 20px;
    }
  }
}
</style>
<style>
.msg-pagination-container.is-background .el-pager li:not(.disabled).active {
  /*当前选中页数的样式进行修改*/
  background-color: #0bb197;
  color: #fff;
}
</style>